import useRequest from '../hook/request';
import useUser from "../hook/user";
import axios from 'axios';

// 账户基本信息 
export function getCustomerAccountApi(params: any, id:number) {
  return useRequest(
    `customer/account/getCustomerAccount/${id}`,
    params,
    'GET'
  )
}

// 支付类型
export function getCustomerTypeApi(params: any) {
  return useRequest(
    'pay/order/getCustomerType',
    params,
    'GET'
  )
}

// 获取医生
export function getDoctorUserByStatusAPi(params: any) {
  return useRequest(
    'company/user/user/getDoctorUserByStatus',
    params,
    'POST'
  )
}


// 获取护士
export function getNurseUserByStatusAPi(params: any) {
  return useRequest(
    'company/user/user/getNurseUserByStatus',
    params,
    'POST'
  )
}

// 获取咨询师
export function getConsultUserByStatusAPi(params: any) {
  return useRequest(
    'company/user/user/getConsultUserByStatus',
    params,
    'POST'
  )
}

// 查询当前分院所有用户
export function getUserListsAPi(params: any) {
  return useRequest(
    'company/user/user/getUserList',
    params,
    'GET'
  )
}

// 查询当前分院所有医生（所有）
export function getDoctorListAllAPi(params: any) {
  return useRequest(
    'company/user/user/getDoctorListAll',
    params,
    'GET'
  )
}

// 查询当前分院所有护士（所有）
export function getNurseListAllAPi(params: any) {
  return useRequest(
    'company/user/user/getNurseListAll',
    params,
    'GET'
  )
}

// 查询当前分院所有咨询师（所有）
export function getConsultListAllAPi(params: any) {
  return useRequest(
    'company/user/user/getConsultListAll',
    params,
    'GET'
  )
}

// 修改自己的密码
export function updateSelfPasswordAPi(params: any) {
  return useRequest(
    'sys/index/updateSelfPassword',
    params,
    'POST'
  )
}

// 添加图片
export function addImageAPi(params: any) {
  return useRequest(
    `sick/image/addImage`,
    params,
    'POST'
  )
}


// 添加图片 批量
export function addImageListAPi(params: any) {
  return useRequest(
    `sick/image/addImageList`,
    params,
    'POST'
  )
}

// 删除图片
export function delImageAPi(params: any, id: number) {
  return useRequest(
    `sick/image/delImage/${id}`,
    params,
    'POST'
  )
}

// 获取患者头部信息
export function getCustomerInfoAPi(params: any, id: number) {
  return useRequest(
    `customer/info/getCustomerInfo/${id}`,
    params,
    'GET'
  )
}


export const download = (blob:any, name:string) => {
  const link = document.createElement('a'); //创建一个a标签
  const url = URL.createObjectURL(blob); //将blob文件对象通过URL.createObjectURL()方法转为为url
  link.href = url; //为a标签设置href属性，并赋值为url
  link.download = name; //定义下载的文件名，文件名要包含后缀哟！如'导出EXCEL.xlsx'
  document.body.appendChild(link); //把a标签放在body上
  link.click(); //出发a标签点击下载
  document.body.removeChild(link); //在body中移除这个a标签
  URL.revokeObjectURL(url); //释放blob对象
}

const baseUrl: string = (
	(import.meta.env.VITE_API_BASE_URL as string) ? import.meta.env.VITE_API_BASE_URL : "/"
) as string;
// 导出
const user = useUser();
const instance = axios.create({
  baseURL: baseUrl,
  // timeout: 20000,
  headers: {Token: user.getToken()}
});

export function cashFlowExportAPi(path:string,params: any) {
  return instance.post(
    path,
    params,
    { responseType: 'blob' }
  )
}





